import pandas as pd
from sklearn.linear_model import LinearRegression, Ridge, Lasso
import matplotlib.pyplot as plt


data = pd.read_csv('GDP.csv')
year = data.loc[::-1, 'Year'].to_numpy().reshape(-1,1)
gdp = data.loc[::-1, 'Jiangsu'].to_numpy()
print(year)
print(gdp)
model1 = LinearRegression()
model1.fit(year, gdp)
print(model1.predict([[2021]]))
print(model1.coef_, model1.intercept_)

model2 = Ridge(alpha=2.0)
model2.fit(year, gdp)
print(model2.predict([[2021]]))

model3 = Lasso(alpha=4)
model3.fit(year, gdp)
print(model3.predict([[2021]]))

plt.plot(year, gdp)
xm = year.reshape(-1)
ym = model1.coef_[0]*year + model1.intercept_
plt.plot(xm, ym)
plt.show()
